package com.jvm.classloader;

/**
 * 初始化一个类是按照从上至下的顺序初始化的
 */
public class MyTest6 {
    public static void main(String[] args) {
        Singleton singleton = Singleton.getInstence();
        System.out.println("count1: " + Singleton.count1);
        System.out.println("count2: " + Singleton.count2);
    }
}

class Singleton{

    public static int count1 = 1;

    //public static int count2 = 0;

    private static Singleton singleton = new Singleton();

    private Singleton(){
        count1++;
        count2++;//准备阶段的重要意义，这里准备阶段会给一个初始值0，否则无法++

        System.out.println(count1);
        System.out.println(count2);
    }

    public static int count2 = 0;

    public static Singleton getInstence(){
        return singleton;
    }
}
